//
//  HCLogViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/22.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCLogViewController.h"

#import "HCLogInView.h"
#import "HCRegisteredViewController.h"
#import "HCForgetViewController.h"

@interface HCLogViewController () <HCLogInViewDelegate>

@end

@implementation HCLogViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.headerView.hidden = YES;
    
    CGRect makeRect = CGRectMake(0, 0, YBKWinFrame.size.width, YBKWinFrame.size.height);;
    self.view.frame = makeRect;
    
    
    HCLogInView *log = [[HCLogInView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    log.delegate = self;
    [self.view addSubview:log];

    self.dataRequest.delegate = self;
    
    // Do any additional setup after loading the view.
}

-(void)logInViewForgetPwd {
    HCForgetViewController *vc = [[HCForgetViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
//    [self pushChildrenViewController:@"" parameterObject:nil dataObject:nil];
}

-(void)logInViewLogClicked {
    
    HCRegisteredViewController *vc = [[HCRegisteredViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
}

-(void)logInViewLogInClicked:(NSString *)phone password:(NSString *)pwd {
    NSLog(@"登录");
    if (([PublicFunction isNull:phone]) && ([PublicFunction isNull:pwd])) {
        [XHToast showBottomWithText:@"有必填项未填写"];
    }else{
        [self.dataRequest postHC_Login:phone password:pwd];
    }
    
}

-(void)logInViewCancle {
    //取消
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"取消登录");
    }];
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {
    NSLog(@"登录成功:%@",dictionary);
    
    if ([dictionary[@"stat"] integerValue] == 400) {
        [XHToast showBottomWithText:@"登录失败"];
    }else if ([dictionary[@"stat"] integerValue] == 200) {
        HCUSERDEFUALTS(dictionary[@"id"], @"userid");
        HCUSERDEFUALTS(dictionary[@"phone"], @"hcphone");
        [self dismissViewControllerAnimated:YES completion:^{
            [XHToast showBottomWithText:@"登录成功"];
        }];
    }
    
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    NSLog(@"登录失败");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
